package com.yanqu.road.server.manger.activity.jinli;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.jinli.config.JinLiConfig;
import com.yanqu.road.entity.enums.eActivityConfigType;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.logic.bussiness.servercenter.ActivityBussiness;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.jinli.JinLiModule;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;

import java.util.Collections;
import java.util.List;
import java.util.Map;

public class JinLiMgr extends TempMgr {

    private static JinLiConfig config = null;

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return false;
    }

    /**
     * 加载活动
     */
    public static void reloadActivityData() {
        getLogger().info("reload JinLi Activity start");
        List<ActivityInfo> list = NormalActivityMgr.getOpenActivityInfoList(eActivityType.JinLi.getValue());
        if (list.isEmpty()) {
            getLogger().info("no JinLi Activity in show time");
            config = null;
            return;
        }
        JinLiConfig tempConfig = new JinLiConfig();
        tempConfig.setActivityInfo(list.get(0));
        Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(tempConfig.getActivityInfo().getActivityId());
        if (activityConfigMap.containsKey(eActivityConfigType.LUCKYSHOP_LV_LIMIT.getName())) {
            tempConfig.setLvLimit(activityConfigMap.get(eActivityConfigType.LUCKYSHOP_LV_LIMIT.getName()).getIntValue());
        }
        config = tempConfig;

        //  推送
        List<GamePlayer> allOnlinePlayer = GamePlayerMgr.getAllOnlinePlayer();
        for (GamePlayer player : allOnlinePlayer) {
            // 同步下数据
            player.getModule(JinLiModule.class).initSystem();
        }
        getLogger().info("reload JinLi Activity end");
    }

    public static JinLiConfig getConfig() {
        return config;
    }
}
